using System;
using System.Collections.Generic;
using System.Text;
using Slf.Formatters;

namespace Slf.Samples.FormattingSample
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.ForegroundColor = ConsoleColor.Green;
      Console.Out.WriteLine("Log item formatters allow you to easily control the transformation of a LogItem info a string.");
      Console.Out.WriteLine("This sample uses a ConsoleLogger with two different formatters to change the output on the console.\n\n");
      Console.ResetColor();


      //create logger and plug in custom formatter
      IFormattableLogger logger = new ConsoleLogger();
      logger.Formatter = new XmlFormatter();

      LoggerService.SetLogger(logger);

      Console.WriteLine("Formatting item with XML formatter:\n");
      SayHelloWorld();

      //plug in a delegate formatter
      logger.Formatter = new DelegateLogItemFormatter(li => li.LogLevel + ": " + li.Message);

      Console.WriteLine("\n\nFormatting item with delegate formatter:");
      SayHelloWorld();

      Console.ReadLine();
    }


    private static void SayHelloWorld()
    {
      ILogger logger = LoggerService.GetLogger();
      logger.Info("hello world");
    }
  }
}